/**
 * 
 */
package com.sad.dao.impl;

import java.io.IOException;
import java.util.Map;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import com.sad.dao.BaseRecord;
import com.sad.model.JsonObject;
import com.sad.model.Wish;
import com.sad.util.G;

/**
 * @author zhaoqy
 *
 */
public class WishRecord extends BaseRecord<Wish> {

	@Override
	protected String getUrl(Map<String, Object> parms) {

		String url = "";
		String action = (String) parms.get("action");

		if ("create".equals(action)) {
			String wishid = (String) parms.get("wishid");

			url = G.system.url + "/toy/order/create?wishid=" + wishid;
		} else if ("table".equals(action)) {
			String page = (String) parms.get(G.K.page);
			String pageSize = (String) parms.get(G.K.perPage);
			
			url = G.system.url + "/toy/wish/wishlist?status=w,o&pageNo=" + page + "&pageSize="
					+ pageSize;
		}

		return url;
	}

	@Override
	protected JsonObject<Wish> parserJsonObject(String json) throws JsonParseException,
			JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.readValue(json, new TypeReference<JsonObject<Wish>>() {
		});
	}

}
